module.exports = function ($scope, $state, $resource, $timeout, $stateParams, stateup, statedown, delflgdel, toaster, $modal) {

/* 分页
  * ========================================= */
  $scope.maxSize = 5;            //最多显示多少个按钮
  $scope.bigCurrentPage = 1;      //当前页码
  $scope.itemsPerPage = 10;         //每页显示几条
  $scope.searchform = {};

  $scope.load = function () {
      var para = {
        name:$scope.searchform.name,
        pageNo: $scope.bigCurrentPage,
        pageSize: $scope.itemsPerPage,
      };
      para = angular.extend($scope.searchform, para);
      $resource('/api/as/ggc/railmapdao/findScenicAreaList', {}, {}).save(para,function (res) {

        if (res.errcode !== 0) {
          alert("数据获取失败");
          return;
        }
  
        $scope.objs = res.data.results;
        $scope.bigTotalItems = res.data.totalRecord;
        $scope.bigCurrentPage = res.data.pageNo;
  
      });
  };
  $scope.load();
	$scope.myKeyup = function (e) {

		//IE 编码包含在window.event.keyCode中，Firefox或Safari 包含在event.which中
		var keycode = window.event ? e.keyCode : e.which;
		if (keycode == 13) {
			$scope.load();
		}
  };
  
  //上架
	$scope.stateup = function (code) {
		stateup.get({ 'code': code }, function (res) {
			if (res.errcode === 0) {
        toaster.success({ title: "提示", body: "上架成功！"});
				$scope.load();
			} else {
				toaster.error({ title: "提示", body: res.errmsg });
			}
		});
  };
    //下架
	$scope.statedown = function (code) {
		statedown.get({ 'code': code }, function (res) {
			if (res.errcode === 0) {
        toaster.success({ title: "提示", body: "下架成功！"});
				$scope.load();
			} else {
				toaster.error({ title: "提示", body: res.errmsg });
			}
		});
  };
    //删除
	$scope.delflgdel = function (code) {
    if(confirm("您确认要删除吗？")){
      delflgdel.get({ 'code': code }, function (res) {
        if (res.errcode === 0) {
          toaster.success({ title: "提示", body: "删除成功！"});
          $scope.load();
        } else {
          toaster.error({ title: "提示", body: res.errmsg });
        }
      });
    }
  };
  
  $scope.lookthisspot = function(code){
    $state.go('app.scenicSpotList',{'code' : code});
  }

  $scope.add = function(param){
    var modalInstance = $modal.open({
        template: require('../views/CreateArea.html'),
        controller: 'createArea',
        size: 'lg',
        resolve: {
            param:function(){
              return param;
            }
        }
    });
    modalInstance.result.then(function (showResult) {	
      $scope.load();
    });
    
};


}